﻿/*
 *********************************************************************
 *    Management Extensions for Windows Windows Server AppFabric     *
 *********************************************************************
 *    Author    : Fatih Boy [fatih@enterprisecoding.com]             *
 *    Web site  : http://www.enterprisecoding.com                    *
 *********************************************************************
 *    License   : GNU Library General Public License (LGPL)          * 
 *********************************************************************
 */

using System.Collections;

using Com.Enterprisecoding.AppFabric.Extensions.Client.Resources;
using Microsoft.Web.Management.Client;
using Microsoft.Web.Management.Client.Win32;
using System.Collections.Generic;
using Com.Enterprisecoding.AppFabric.Extensions.Client.Resources.Cache;

namespace Com.Enterprisecoding.AppFabric.Extensions.Client.Pages.Cache.Accounts {
    internal sealed class CacheAccountsTaskList : TaskList {
        #region Data Members
        //private PowershellHost host = new PowershellHost();
        private CacheAccountsPage owner;

        private MethodTaskItem addAccountTaskItem;
        internal MethodTaskItem removeAccountTaskItem;
        internal MessageTaskItem noAccountTaskItem;
        #endregion

        public CacheAccountsTaskList(CacheAccountsPage owner) {
            this.owner = owner;

            addAccountTaskItem = new MethodTaskItem("AddAccount", Resources.Cache.CacheAccountsPage.AddAccountTaskItemText, "Tasks", Resources.Cache.CacheAccountsPage.AddAccountTaskItemDescription, Properties.Resources.user_add);
            removeAccountTaskItem = new MethodTaskItem("RemoveAccount", Resources.Cache.CacheAccountsPage.RemoveAccountTaskItemText, "Tasks", Resources.Cache.CacheAccountsPage.RemoveAccountTaskItemDescription, Properties.Resources.user_delete);

            noAccountTaskItem = new MessageTaskItem(MessageTaskItemType.Information, Resources.Cache.CacheAccountsPage.NoAccountListedMessage, "Info");
        }

        public override ICollection GetTaskItems() {
            if (owner.InProgress) { return new TaskItem[0]; }

            var taskItems = new List<TaskItem>();
            taskItems.Add(addAccountTaskItem);

            if (!owner.HasAllowedAccount) {
                taskItems.Add(noAccountTaskItem);
            }

            if (owner.HasSelectedAccount) {
                taskItems.Add(removeAccountTaskItem);
            }

            return taskItems;
        }

        public void AddAccount() {
            owner.AddAccount();
        }

        public void RemoveAccount() {
            owner.RemoveAccount();
        } 
    }
}